import App from './App'

import Vue from 'vue'
import VueRouter from 'vue-router'
import store from './store'
import Axios from 'axios'
import routes from './router/index.js'

import MintUI from 'mint-ui'
import FastClick from 'fastclick'
import 'lib-flexible/flexible.js'
import moment from 'moment'
import VuePreview from 'vue-preview'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import mui from '@/assets/mui/js/mui.min.js'


import "normalize.css"
import "mint-ui/lib/style.css"
import "./assets/mui/css/mui.min.css" /* no */
import "../static/css/global.scss"
import 'swiper/dist/css/swiper.css'

Vue.use(MintUI);
Vue.use(VuePreview, {
  mainClass: 'pswp--minimal--dark',
  barsSize: {top: 90, bottom: 0},
  captionEl: false,
  fullscreenEl: false,
  shareEl: false,
  bgOpacity: 0.85,
  tapToClose: true,
  tapToToggleControls: false
});
Vue.use(VueAwesomeSwiper, /* { default global options } */)

Vue.filter('dateFormat', function (dataStr, pattern = "YYYY-MM-DD") {
  if (dataStr == '开始日期' || dataStr == '结束日期') {
    return dataStr;
  }
  return moment(dataStr).format(pattern)
})

Object.defineProperty(Vue.prototype, '$axios', {
  get () {
    return Axios
  }
});
Object.defineProperty(Vue.prototype, '$moment', {
  get () {
    return moment
  }
});
Object.defineProperty(Vue.prototype, '$mui', {
  get () {
    return mui
  }
});



// FastClick.attach(document.body)

const router = new VueRouter({
  routes,
  scrollBehavior (to, from, savedPosition) {
    return { x: 0, y: 0 }
  }
})

import vmCommonExamineProcess from '@/components/vm-common-examine-process.vue'
Vue.component('vm-common-examine-process', vmCommonExamineProcess);
import vmCommonNoData from '@/components/vm-common-noData/vm-common-no-data.vue'
Vue.component('vm-common-noData',vmCommonNoData);


import { userIsLogin } from '@/utils/userHandler.js'
router.beforeEach((to, from, next) => {
  if ( to.meta.isLogin ) {
    // 需要登录才可以访问
    if ( userIsLogin() ) {
      next();
    } else {
      router.push({
        path: '/login'
      });
    };
  } else {
    next();
  }
})
Vue.config.productionTip = false

window.vm = new Vue({
  store,
  router,
  render: r => r(App),
  data: {
    Bus: new Vue()
  }
}).$mount('#app')
